using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BANSACH.BusinessLayer.DataLayer;
using BANSACH.BusinessLayer;
namespace BANSACH_GUI
{
    public partial class frmQuyenmenuDetail : FormBase
    {
        public EventHandler OnAddOrEditEntity;
        private bool _isNew;
        private QuyenmenuFactory objDao;
        private Quyenmenu _Entity;

        public Quyenmenu Entity
        {
            get { return _Entity; }
            set { _Entity = value; }
        }
        public frmQuyenmenuDetail()
        {
            InitializeComponent();
            _isNew = true;
            btnSave.Text = "Lưu && thêm mới";
            _Entity = new Quyenmenu();
        }
        public frmQuyenmenuDetail(Quyenmenu EntityEdit)
        {
            InitializeComponent();
            _isNew = false;
            btnSave.Text = "Lưu";
            _Entity = EntityEdit;
            ViewEntity();
        }
        private void frmQuyenmenuDetail_Load(object sender, EventArgs e)
        {
            objDao = new QuyenmenuFactory();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            SetEntityValue();
            if (_isNew)
            {
                if (objDao.Insert(_Entity))
                {
                    if (OnAddOrEditEntity != null) OnAddOrEditEntity(_Entity, e);
                    NewItem();
                }
            }
            else
            {
                if (objDao.Update(_Entity))
                {
                    if (OnAddOrEditEntity != null) OnAddOrEditEntity(_Entity, e);
                    this.Close();
                }
            }
        }
        private void NewItem()
        { 
            
				 txt_maquyen.Text ="";
				 txt_menuma.Text ="";
        }
        private void ViewEntity()
        { 
            
				 txt_maquyen.Text = _Entity.Maquyen.ToString();
				 txt_menuma.Text = _Entity.Menuma;
        }
        private void SetEntityValue()
        {
            
				 _Entity.Maquyen=txt_maquyen.IntValue.Value;
				 _Entity.Menuma=txt_menuma.Text;
        }
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }       
    }
}
